<template>
  <div class="con">
    <div class="contbox6_10">
      <p class="titlelist6_10">
        商学院
        <span style="color: #999">&nbsp;&nbsp;/&nbsp;&nbsp;</span>内容管理
      </p>
      <div class="content">
        <div class="sousuojg6_10">
          <el-form ref="form" :model="form" label-width="100px">
            <el-form-item label="内容名称" style="float: left">
              <el-input
                v-model="form.resourceTitle"
                placeholder="请输入内容名称"
              ></el-input>
            </el-form-item>
            <el-form-item label="上传人" style="float: left">
              <el-input
                v-model="form.uploadName"
                placeholder="请输入上传人"
              ></el-input>
            </el-form-item>
            <el-form-item label="创建时间">
              <el-date-picker
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="开始日期"
                v-model="form.createStartDate"
                style="width: 100%"
              ></el-date-picker>
              <div class="times">-</div>
              <el-date-picker
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="结束日期"
                v-model="form.createEndDate"
                style="width: 100%"
              ></el-date-picker>
            </el-form-item>
            <!-- <el-form-item label="状态" style="float: left">
              <el-select v-model="form.region" placeholder>
                <el-option label="全部" value=""></el-option>
                <el-option label="已发布" value="0"></el-option>
                <el-option label="未发布" value="1"></el-option>
              </el-select>
            </el-form-item> -->
          </el-form>
        </div>
        <div class="buttons">
          <el-button type="primary" @click="handleSelectLists">搜索</el-button>
          <el-button @click="resetTheSearch">重置</el-button>
          <el-button @click="createFile" style="margin-left:30px">新增文件</el-button>
        </div>
        <el-table
          :data="list"
          tooltip-effect="dark"
          :header-cell-style="{ background: '#F9FAFC', color: '#222' }"
          stripe
          border
          :row-style="{ height: '0px' }"
          :cell-style="{ padding: '0px' }"
          ref="multipleTable"
        >
          <el-table-column
            min-width="200"
            label="内容名称"
            prop="resourceTitle"
          ></el-table-column>
          <el-table-column
            min-width="160"
            label="上传人员"
            prop="uploadName"
          ></el-table-column>
          <el-table-column
            min-width="160"
            label="创建时间"
            prop="createDate"
          ></el-table-column>
          <!-- <el-table-column
            min-width="160"
            label="状态"
            prop="createDate"
          ></el-table-column> -->
          <el-table-column
            min-width="160"
            label="修改时间"
            prop="updateDate"
          ></el-table-column>
          <el-table-column show-overflow-tooltip min-width="200" label="操作">
            <template slot-scope="scope">
              <el-button type="text" @click="cat(scope.row)">查看</el-button>
              <el-button type="text" @click="set(scope.row)">修改</el-button>
              <el-button type="text" @click="move(scope.row, 0)"
                >上移</el-button
              >
              <el-button type="text" @click="move(scope.row, 1)"
                >下移</el-button
              >
              <el-button type="text" @click="delList(scope.row)"
                >删除</el-button
              >
            </template>
          </el-table-column>
        </el-table>
        <div style="font-size: 16px; margin-top: 30px">
          <el-pagination
            style="text-align: right"
            background
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page.sync="form.page"
            :page-sizes="[20, 50, 100]"
            :page-size="form.number"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total"
          ></el-pagination>
        </div>
      </div>
      <el-dialog
        title="删除确认"
        :visible.sync="dialogFormWindows"
        width="500px"
        :close-on-click-modal="false"
      >
        确认删除该内容？
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogFormWindows = false">取 消</el-button>
          <el-button type="primary" @click="create('form')">确 定</el-button>
        </div>
      </el-dialog>
    </div>
  </div>
</template>

<script>
import https from "../../plugins/https.js";
import { CompareDate } from "../../assets/js/commion";
import axios from "axios";
export default {
  data() {
    return {
      dialogFormWindows: false,
      val: "",
      total: 0,
      form: {
        resourceTitle: "", //内容名称
        uploadName: "", //上传人员
        createDate: "", //上传时间
        updateDate: "", //修改时间
        createStartDate: "",
        createEndDate: "",
        page: 1,
        number: 20,
      },
      list: [],
      bussinessType: [],
    };
  },
  created() {
    this.lists();
  },
  methods: {
    //   查看
    cat(val) {
      this.$router.push({
        name: "uploadFile",
        query: {
          perationType: "see",
          id: val.id,
        },
      });
    },
    // 修改
    set(val) {
      this.$router.push({
        name: "uploadFile",
        query: {
          perationType: "modify",
          id: val.id,
        },
      });
    },

    //   新增文件
    createFile() {
      this.$router.push({
        name: "uploadFile",
      });
    },
    //   删除
    delList(val) {
      axios
        .post("api/school/saveSchoolResourse", {
          id: val.id,
          delFlag: "1",
          resourceName: val.resourceName,
        })
        .then((res) => {
          console.log(res);
          if (res.data.code == "0000") {
            this.lists();
          } else {
            layer.open({
              content: res.data.msg,
              skin: "msg",
              time: 1, //1秒后自动关闭
            });
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
    //   上/下移
    move(val, num) {
      axios
        .post("api/school/changeSchoolResourseSort", {
          id: val.id,
          sortType: num,
        })
        .then((res) => {
          console.log(res);
          if (res.data.code == "0000") {
            this.lists();
          } else {
            layer.open({
              content: res.data.msg,
              skin: "msg",
              time: 1, //1秒后自动关闭
            });
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },

    //   获取列表数据
    lists() {
      axios
        .post("api/school/schoolResourceList", this.form)
        .then((res) => {
          this.list = res.data.data;
          console.log(res);
          this.total = res.data.total;
        })
        .catch((err) => {
          console.log(err);
        });
    },
    //搜索
    handleSelectLists() {
      if (this.form.createStartDate != "" && this.form.createEndDate != "") {
        if (CompareDate(this.form.createStartDate, this.form.createEndDate)) {
          this.form.page = 1;
          this.lists();
        } else {
          layer.open({
            content: "结束时间不能早于开始时间",
            skin: "msg",
            time: 1, //1秒后自动关闭
          });
        }
      }else{
        this.form.page = 1;
          this.lists();
      }
    },
    // 校验时间的一个方法
    warrys() {
      layer.open({
        content: "结束时间不能早于开始时间",
        skin: "msg",
        time: 2, //1秒后自动关闭
      });
    },
    // 重置
    resetTheSearch() {
      (this.form = {
        resourceTitle: "", //内容名称
        uploadName: "", //上传人员
        createDate: "", //上传时间
        updateDate: "", //修改时间
        page: 1,
        number: 20,
      }),
        this.lists();
    },
    //每页几条数据
    handleSizeChange(val) {
      this.SelectData = [];
      this.form.number = val; //动态改变
      this.form.page = 1;
      this.lists();
    },
    //当前页
    handleCurrentChange(val) {
      this.SelectData = [];
      this.form.page = val; //动态改变
      this.lists();
    },
  },
};
</script>

<style scoped>
.con {
  position: relative;
}
/* 单独样式 */
.contbox6_10 {
  width: 100%;
  overflow-x: auto;
  box-sizing: border-box;
  float: left;
}
.sousuojg6_10 {
  width: 100%;
}
.times {
  width: 20px;
  display: inline-block;
  text-align: center;
}
.buttons > .el-button {
  width: 100px;
  padding: 7px;
  height: 32px;
}
</style>